﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace LabMS.Web.CoursePlan
{
    public partial class CourseOutLinePreview : Base.BasePage
    {
        public string AttachmentName = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            strPageUserType.Add("mana");
            strPagePrivilege.Add("KCXYM");

            if (Request.QueryString["ID"] != null)
            {
               
                if (!IsPostBack)
                {
                    int ID;
                    if(int.TryParse(Request.QueryString["ID"].ToString(),out ID))
                    {
                        BindData(ID);
                    }
                }
            }
            else
            {
                ERRLbl.Text = "系统异常，参数为空！";
                ERRLbl.Visible=true;
                modifybtn.Visible = false;
            }
        }

        protected void BindData(int ID)
        {
            LabMS.BLL.CourseOutLine couOutLin = new LabMS.BLL.CourseOutLine();
            List<LabMS.Model.CourseOutLine> couOutLinModel = new List<LabMS.Model.CourseOutLine>();

            string strWhere = " COutLine_CourseID=" + ID;
            couOutLinModel = couOutLin.GetModelList(strWhere);
            try
            {
                CouOutLinIDHF.Value = couOutLinModel[0].ID.ToString();
                tb_Submitter.Text = couOutLinModel[0].COutLine_Submiter;
                tb_Time.Text = string.Format("{0:d}", couOutLinModel[0].COutLine_SubmitTime);
                tb_CourseName.Text = couOutLinModel[0].COutLine_Course;
                tb_CourseCode.Text = couOutLinModel[0].COutLine_CourseCode;
                tb_KeyWord.Text = couOutLinModel[0].COutLine_KeyWord;
                tb_Content.Text = couOutLinModel[0].COutLine_Content.Replace("\r\n", "<br/>");

                if (couOutLinModel[0].COutLine_Attach == null)
                {
                    a1.Attributes.Remove("onclick");
                    AttachmentName = "无附件";
                }
                else
                {
                    AttachID.Value = couOutLinModel[0].COutLine_Attach.ToString();
                    AttachmentName = GetAttachName(int.Parse(couOutLinModel[0].COutLine_Attach.ToString()));
                }
            }
            catch
            {
                ERRLbl.Text = "系统异常，参数不合法！";
                ERRLbl.Visible=true;
                modifybtn.Visible = false;
            }
        }

        protected string GetAttachName(int ID)
        {
            LabMS.BLL.Attachment att = new LabMS.BLL.Attachment();
            LabMS.Model.Attachment attModel = new LabMS.Model.Attachment();

            attModel = att.GetModel(ID);

            return attModel.Attach_Name;
        }

        protected void tbDelete_Click(object sender, EventArgs e)
        {
            int CourseID = int.Parse(Request.QueryString["ID"]);
            ExtendBLL.CourseOutLine courseoutline = new ExtendBLL.CourseOutLine();
            string strWhere = " where COutLine_CourseID=" + CourseID;
            try
            {
                courseoutline.Del(strWhere);
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('删除成功!');window.location.href='../ClassPlan/ProjectCourseList.aspx';</script>");
            }
            catch
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('删除失败!');</script>");
            }
        }
    }
}
